package com.hjduan.spring.cloud.provider;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;

@RestController
public class UserController {
	@Autowired
	private EurekaClient eurekaClient;
	@Autowired
	private DiscoveryClient discoveryClient;

	@GetMapping(value = "eureka-instance")
	public String serviceUrl() {
		InstanceInfo instance = eurekaClient.getNextServerFromEureka("HJDUAN-SPRING-CLOUD-CONSUMER", false);
		return instance.getHomePageUrl();
	}

	@SuppressWarnings("deprecation")
	@GetMapping(value = "instance-info")
	public ServiceInstance showInfo() {
		ServiceInstance localServiceInstance = this.discoveryClient.getLocalServiceInstance();
		return localServiceInstance;
	}

	/*@Autowired
	RestTemplate restTemplate;

	@GetMapping(value = "/hi/{name}")
	public String ribbonHelloWordService(@PathVariable String name) {
		return restTemplate.getForObject("http://HJDUAN-SPRING-CLOUD-CONSUMER/hi/{name}", String.class, name);
	}*/
}
